package com.lee.member.mapper;

import com.lee.member.entity.MemberUser;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @author zfl_a
 * @date 2020/4/5
 * @project login-authorization-parent
 */
public interface MemberUserMapper {

    @Insert("INSERT INTO `member_user`(user_id,user_name,password,sex,age,qq_open_id" +
            ",wx_open_id,is_del,create_time,mobile) VALUES (#{userId}, #{userName},#{password}, #{sex}, #{age}, #{qqOpenId}, #{wxOpenId}, #{idDel}," +
            " #{createTime}, #{mobile});\n")
    int register(MemberUser memberUser);

    @Select("SELECT user_id AS userId ,mobile AS mobile ,password as password\n" +
            ",user_name as username ,sex as sex,age as age \n" +
            ",create_time as createTime,is_del as isDel\n" +
            ",\n" +
            "qq_open_id as qqOpenId ,wx_open_id as wxOpenId\n" +
            "\n" +
            "from member_user  where mobile=#{mobile} and password=#{passWord}")
    MemberUser login(@Param("mobile")String mobile, @Param("password")String passWord);

    @Select("SELECT user_id AS userId ,mobile AS mobile ,password as password\n" +
            ",user_name as username ,sex as sex,age as age \n" +
            ",create_time as createTime,is_del as isDel\n" +
            ",\n" +
            "qq_open_id as qqOpenId ,wx_open_id as wxOpenId\n" +
            "\n" +
            "from member_user  where mobile=#{mobile}")
    MemberUser existMobile(String mobile);

    @Select("SELECT user_id AS userId ,mobile AS mobile ,password as password\n" +
            ",user_name as username ,sex as sex,age as age \n" +
            ",create_time as createTime,is_del as isDel\n" +
            ",\n" +
            "qq_open_id as qqOpenId ,wx_open_id as wxOpenId\n" +
            "\n" +
            "from member_user  where user_id=#{userId}")
    MemberUser findByUser(String userId);

    @Update("\n" +
            "update member_user set wx_open_id=#{wxOpenId}  where user_id=#{userId};")
    int updateUseWxOpenId(@Param("userId") Long userId, @Param("wxOpenId") String wxOpenId);

    @Select("SELECT user_id AS userId ,mobile AS mobile ,password as password\n" +
            ",user_name as username ,sex as sex,age as age \n" +
            ",create_time as createTime,is_del as isDel\n" +
            ",\n" +
            "qq_open_id as qqOpenId ,wx_open_id as wxOpenId\n" +
            "\n" +
            "from member_user  where wx_open_id=#{wxOpenId}")
    MemberUser selectByWxOpenId(@Param("wxOpenId") String wxOpenId);


    @Update("\n" +
            "update member_user set wx_open_id=null  where wx_open_id=#{wxOpenId};")
    int cancelFollowOpenId(@Param("wxOpenId") String wxOpenId);
}
